package com.app.biz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.app.biz.utils.ChatMessageUtils;
import com.app.common.annotation.Log;
import com.app.common.core.controller.BaseController;
import com.app.common.core.domain.AjaxResult;
import com.app.common.core.page.TableDataInfo;
import com.app.common.enums.BusinessType;
import com.app.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.app.biz.domain.BizAppChatMsg;
import com.app.biz.service.IBizAppChatMsgService;


/**
 * app聊天记录Controller
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/system/msg")
public class BizAppChatMsgController extends BaseController
{
    @Autowired
    private IBizAppChatMsgService bizAppChatMsgService;

    @Autowired
    private ChatMessageUtils chatMessageUtils;

    /**
     * 查询app聊天记录列表
     */
    //@PreAuthorize("@ss.hasPermi('system:msg:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizAppChatMsg bizAppChatMsg)
    {
        startPage();
        List<BizAppChatMsg> list = bizAppChatMsgService.selectBizAppChatMsgList(bizAppChatMsg);
        return getDataTable(list);
    }

    /**
     * 导出app聊天记录列表
     */
    //@PreAuthorize("@ss.hasPermi('system:msg:export')")
    @Log(title = "app聊天记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizAppChatMsg bizAppChatMsg)
    {
        List<BizAppChatMsg> list = bizAppChatMsgService.selectBizAppChatMsgList(bizAppChatMsg);
        ExcelUtil<BizAppChatMsg> util = new ExcelUtil<BizAppChatMsg>(BizAppChatMsg.class);
        util.exportExcel(response, list, "app聊天记录数据");
    }

    /**
     * 获取app聊天记录详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:msg:query')")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(bizAppChatMsgService.selectBizAppChatMsgByBaseId(baseId));
    }

    /**
     * 新增app聊天记录
     */
    //@PreAuthorize("@ss.hasPermi('system:msg:add')")
    @Log(title = "app聊天记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizAppChatMsg bizAppChatMsg)
    {
        return success(bizAppChatMsgService.insertBizAppChatMsg(bizAppChatMsg));
    }

    /**
     * 修改app聊天记录
     */
    //@PreAuthorize("@ss.hasPermi('system:msg:edit')")
    @Log(title = "app聊天记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizAppChatMsg bizAppChatMsg)
    {
        return success(bizAppChatMsgService.updateBizAppChatMsg(bizAppChatMsg));
    }

    /**
     * 删除app聊天记录
     */
    //@PreAuthorize("@ss.hasPermi('system:msg:remove')")
    @Log(title = "app聊天记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return success(bizAppChatMsgService.deleteBizAppChatMsgByBaseIds(baseIds));
    }

    //@PreAuthorize("@ss.hasPermi('system:msg:add')")
    @Log(title = "处理app聊天记录", businessType = BusinessType.INSERT)
    @PostMapping("/dealMessage")
    public AjaxResult dealMessage(@RequestBody BizAppChatMsg bizAppChatMsg)
    {
        chatMessageUtils.saveAndSendMessage(bizAppChatMsg);
        return success();
    }
}
